//
//  Creator.h
//  RenderV1
//
//  Created by 黄翔 on 2019/10/20.
//  Copyright © 2019 黄翔. All rights reserved.
//

#ifndef Creator_h
#define Creator_h
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include "render_v1.h"

namespace hxe {
class Material;
class Meshes;
    class Creator
    {
    public:
        static Light* createLight(Vector3 position, Vector3 eularAngle,
                                   Color lightColor = Color(1.0f, 1.0f, 1.0f, 1.0f),
                                   Color ambientColor = Color(0.1f, 0.1f, 0.1f, 1.0f));
        
        static Camera* createCamera(Vector3 position, Vector3 forward, Vector3 up, float fov, float aspect, float near, float far);

        static Camera* createUICamera(Vector3 position, Vector3 forward, Vector3 up, float orthographicSize, float aspect, float near, float far);
        
        static GameObject* createModel(std::string path, Vector3 position = Vector3(0.0f,0.0f,0.0f), std::string name = "");

        static Mesh* createPlaneMesh(float width, float height, int horizontalCount, int verticalCount);
        
        static GameObject* createPlane(float width, float height, int horizontalCount, int verticalCount);
        
        static Mesh* createCubeMesh(float length, float width, float height);
        
        static GameObject* createCube(float length, float width, float height);
        
        static Mesh* createSphereMesh(float radius, unsigned int row, unsigned int col);
        
        static GameObject* createSphere(float radius, unsigned int row, unsigned int col);

        static GameObject* createRobot(Color color);

        static SkyBox* createSkyBox();

        static Mesh* createImageMesh(float width, float height);

        static GameObject* createImage(const std::string& path, float width, float height);
        
    private:
        static void loadModel(std::vector<Mesh*>* meshes, std::vector<Material*>* materials, const std::string& path);
        static void processNode(std::vector<Mesh*>* meshes, std::vector<Material*>* materials,
                                aiNode* node, const aiScene* scene,
                                const std::string directory);
        static Mesh* processMesh(aiMesh* mesh, const aiScene* scene);
        static std::vector<Texture*> processMaterialTextures(aiMaterial *mat, aiTextureType type, std::string typeName, const std::string directory);

        static void genNormals(std::vector<Vector3>* normals, const std::vector<Vector3>* vertices, const std::vector<unsigned int>* indices);
    };
}

#endif /* Creator_h */
